#encoding=utf8
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn import cross_validation, metrics
from sklearn.model_selection import train_test_split
import xgboost as xgb
from sklearn.metrics import accuracy_score

if __name__ == "__main__":
    train = pd.read_csv('../dataset/train_modified.csv')
    target='Disbursed' # Disbursed的值就是二元分类的输出
    IDcol = 'ID'

    x_columns = [x for x in train.columns if x not in [target, IDcol]]
    X = train[x_columns]
    y = train['Disbursed']

    x_train, x_test, y_train, y_test = train_test_split(X, y, train_size=0.7, random_state=1)
    data_train = xgb.DMatrix(x_train, label=y_train)
    data_test = xgb.DMatrix(x_test, label=y_test)
    watch_list = [(data_test, 'test'), (data_train, 'train')]
    param = {'max_depth': 4, 'eta': 0.3, 'silent': 1, 'objective': 'multi:softmax', 'num_class': 2}

    xgb_model = xgb.train(param, data_train, num_boost_round=6, evals=watch_list)
    y_hat = xgb_model.predict(data_test)
    print 'XGBoost正确率：', accuracy_score(y_test, y_hat)
